<?php

namespace Api\Event;


/** 
 * Tag接口
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

class TagEvent extends BaseEvent {


	public function search($title)
	{
		$data = array();
		$title && $map['search'] = array('like', "^{$title}");
		$res = D('Common/Tag', 'Service')->where($map)->select();
		if ($res)
		{
			foreach ($res as $key => $value) {
				$data[] = $value['title'];
			}
		}
		return $data;
	}


	public function refresh()
	{
		$tagServ = D('Common/Tag', 'Service');
		$tags = $tagServ->getField('title', true);
		$vServ = D('Common/Video', 'Service');
		$map['status'] = $vServ::STATUS_PASS;
		foreach ($tags as $tag) {
			$map['tags'] = $tag;
			$count = $vServ->where($map)->count();
			$tagServ->setHot($tag, $count);
		}
	}


	/**
	*获取Tag列表
	*@author susy.liang<susy.liang@ilongyuan.com.cn>
	*/
	public function lists($field=''){

		$tagServ = D('Common/Tag', 'Service');
		$map = array(
				'status'=>$tagServ::STATUS_PASS,
			);
		return $tagServ->where($map)->field($field,true)->select();
	}


	/** 
	 * 获取热门Tag
	 * @author Legend. <xcx_legender@qq.com>
	 * @param 
	 * @return 
	 */
	
	public function getHot($limit = 20)
	{
		$tagServ = D('Common/Tag', 'Service');
		$map = array(
				'status'=>$tagServ::STATUS_PASS,
			);
		$tags = $tagServ->where($map)->order('hot desc')->limit($limit)->getField('title', true);
		return $tags;
	}
	

}
